import { FormSchema } from '/@/components/Table';

const isSQL = (type) => type === 'SQL';
const isFixed= (type) => type === '固定密码';
const isHttp = (type) => type === 'HTTP';
export const formSchema: FormSchema[] = [
  {
    label: 'id',
    field: 'id',
    component: 'Input',
    show: false,
  },
  {
    field: 'name',
    label: '名称',
    component: 'Input',
    required: true,
  },
  {
    field: 'enable',
    label: 'enable',
    component: 'Input',
    show: false,
    defaultValue: false,
  },
  {
    field: 'type',
    label: '类型',
    component: 'Input',
    show: false,
  },
  {
    field: 'driverClassName',
    label: 'JDBC驱动类名',
    component: 'Select',
    componentProps: {
      options: [
        { label: 'com.mysql.cj.jdbc.Driver', value: 'com.mysql.cj.jdbc.Driver' },
        { label: 'oracle.jdbc.OracleDriver', value: 'oracle.jdbc.OracleDriver' },
        { label: 'org.postgresql.Driver', value: 'org.postgresql.Driver' },
        { label: 'com.microsoft.sqlserver.jdbc.SQLServerDriver', value: 'com.microsoft.sqlserver.jdbc.SQLServerDriver' },
      ],
    },
    required: true,
    ifShow: ({ values }) => isSQL(values.type),
  },
  {
    field: 'jdbcUrl',
    label: 'JDBC连接地址',
    component: 'Input',
    required: true,
    ifShow: ({ values }) => isSQL(values.type),
  },
  {
    field: 'username',
    label: '数据库用户名',
    component: 'Input',
    required: true,
    ifShow: ({ values }) => isSQL(values.type),
  },
  {
    field: 'password',
    label: '数据库密码',
    component: 'Input',
    required: true,
    ifShow: ({ values }) => isSQL(values.type),
  },
  {
    field: 'authSql',
    label: '认证SQL',
    component: 'Input',
    defaultValue: "select count(1) from user where username = '${username}' and password = '${password}' and clientId = '${clientId}'",
    required: true,
    ifShow: ({ values }) => isSQL(values.type),
  },
  {
    field: 'fixedAuthConfig',
    label: '添加账号密码',
    component: 'Input',
    slot: 'fixedAuth',
    ifShow: ({ values }) => isFixed(values.type),
  },
  {
    field: 'url',
    label: '请求地址',
    component: 'Input',
    required: true,
    ifShow: ({ values }) => isHttp(values.type),
  },
  {
    field: 'method',
    label: '请求方法',
    component: 'Input',
    slot: 'request',
    ifShow: ({ values }) => isHttp(values.type),
  },
  {
    field: 'headers',
    label: '请求头',
    component: 'JAddInput',
    componentProps: {
      //自定义超过多少行才会显示删除按钮，默认为1
      min: 1,
    },
    ifShow: ({ values }) => isHttp(values.type),
  },
  {
    field: 'params',
    label: '请求参数',
    component: 'JAddInput',
    componentProps: {
      //自定义超过多少行才会显示删除按钮，默认为1
      min: 1,
    },
    ifShow: ({ values }) => isHttp(values.type),
  },
  {
    field: 'filter',
    label: '匹配规则',
    component: 'Input',
    componentProps: {
      placeholder: 'fluxmql{clientId}',
    },
  },
];

export interface ActionBtn {
  img?: string;
  click?: object;
  isshow?: boolean;
  name?: string;
  params?: string;
}

export const actionBtns: ActionBtn[] = [
  {
    img: '',
    click: {
      isshow: false,
      name: 'handleRun',
    },
  },
  {
    img: '',
    click: {
      isshow: false,
      name: 'handleEdit',
    },
  },
  {
    img: '',
    click: {
      isshow: true,
      name: 'handleRun',
    },
  },
  {
    img: '',
    click: {
      defaultshow: true,
      name: 'handleDetail',
    },
  },
  {
    img: '',
    click: {
      isshow: false,
      name: 'handleDelete',
    },
  },
];
export interface AuthType {
  img?: string;
  name?: string;
  desc?: string;
}
export const authType: AuthType[] = [
  {
    img: '',
    name: 'SQL',
    desc: '使用SQL认证, 支持mysql，oracle，pg，sqlServer，td，ck等数据库',
  },
  {
    img: '',
    name: '固定密码',
    desc: '使用固定密码认证',
  },
  {
    img: '',
    name: 'HTTP',
    desc: '使用HTTP认证',
  },
];
